﻿using Maticsoft.Json;
using System.Collections.Generic;
using System.Web.Http;
using Top.Api;
using Top.Api.Request;
using Top.Api.Response;
using ZGEDrySaltery.Api.Controllers;
using ZGEDrySaltery.DTO;

namespace ZGEDrySaltery.Api
{
    /// <summary>
    /// 接口类
    /// </summary>
    public class BMApiController : ApiController
    {
        #region 1、好券清单API【导购】列表  
        /// <summary>
        /// 好券清单API【导购】列表
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonObject GetTbkDgItemCouponList(ParaDTO paraDTO)
        {
            JsonResultDTO jsonResultDTO = new JsonResultDTO();
            string cat = paraDTO.cat == 0 ? "" : paraDTO.cat.ToString();
            TbkDgItemCouponGetResponse rsp = TbkApiHelper.get_dg_coupon_list(1, cat, paraDTO.pagesize, paraDTO.q, paraDTO.page);
            List<Top.Api.Response.TbkDgItemCouponGetResponse.TbkCouponDomain> list = rsp.Results;
            jsonResultDTO.ViewList = list;
            jsonResultDTO.Total = (int)rsp.TotalResults;
            return ModelToJson(jsonResultDTO);
        }
        #endregion

        #region 2、聚划算商品搜索接口
        /// <summary>
        /// 聚划算商品搜索接口
        /// </summary>
        /// <returns></returns>
        [HttpPost]
        public JsonObject GetJuItemsSearchnList(ParaDTO paraDTO)
        {
            JsonResultDTO jsonResultDTO = new JsonResultDTO();
            JuItemsSearchResponse rsp = TbkApiHelper.ju_items_searchn_list(paraDTO.cat, paraDTO.pagesize, paraDTO.q, paraDTO.page);
            jsonResultDTO.ViewList = rsp.Result;
            return ModelToJson(jsonResultDTO);
        }
        #endregion

        #region 实体转化成json串
        /// <summary>
        /// 实体转化成json串
        /// </summary>
        /// <param name="jrDTO"></param>
        /// <returns></returns>
        private JsonObject ModelToJson(JsonResultDTO jrDTO)
        {
            JsonObject obj = new JsonObject();
            obj.Accumulate("Result", jrDTO.Result);
            obj.Accumulate("Msg", jrDTO.Msg);
            obj.Accumulate("ViewList", jrDTO.ViewList);
            obj.Accumulate("Total", jrDTO.Total);

            return obj;
        }
        #endregion

    }
}